<template>
  <basic-container>
    <div class="container-body">
      <el-form :inline="true" :model="query" class="demo-form-inline">
        <el-form-item label="卡户账号">
          <el-input size="small" v-model="query.khzh" placeholder="khzh" clearable></el-input>
        </el-form-item>
        <el-form-item label="卡户姓名">
          <el-input size="small" v-model="query.khxm" placeholder="khxm" clearable></el-input>
        </el-form-item>
        <el-form-item label="商户名称">
          <el-input size="small" v-model="query.shmc" placeholder="shmc" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button size="small" type="primary" icon="el-icon-search" @click="onSearch" :loading="loading">搜索
          </el-button>
          <el-button size="small" icon="el-icon-delete" @click="searchReset" :loading="loading">清空</el-button>
        </el-form-item>
      </el-form>
      <div class="btn-operate">
<!--        <el-button v-if="permissions.adis_adreport05_add" @click="showAddView" type="primary" size="small" icon="el-icon-plus">-->
<!--          新增-->
<!--        </el-button>-->
        <el-button v-if="permissions.sys_user_import_export" class="filter-item" plain type="primary" size="small" icon="el-icon-upload" @click="$refs.excelUpload.show()">导入
        </el-button>
      </div>
      <el-table header-row-class-name="container-table-header"
                :data="data" size="small"
                style="width: 100%;margin-bottom: 20px;"
                row-key="id"
                border stripe
                v-loading="loading">
        <el-table-column prop="djh" label="单据号">
        </el-table-column>
        <el-table-column prop="jyzd" label="交易站点">
        </el-table-column>
        <el-table-column prop="khzh" label="卡户账号">
        </el-table-column>
        <el-table-column prop="khxm" label="卡户姓名">
        </el-table-column>
        <el-table-column prop="khsf" label="卡户身份">
        </el-table-column>
        <el-table-column prop="jylx" label="交易类型">
        </el-table-column>
        <el-table-column prop="jysj" label="交易时间">
        </el-table-column>
        <el-table-column prop="jyje" label="交易金额">
        </el-table-column>
        <el-table-column prop="kaye" label="卡余额">
        </el-table-column>
        <el-table-column prop="kuye" label="库余额">
        </el-table-column>
        <el-table-column prop="shzh" label="商户账号">
        </el-table-column>
        <el-table-column prop="shmc" label="商户名称">
        </el-table-column>
        <el-table-column prop="dzsj" label="到账时间">
        </el-table-column>
        <el-table-column prop="bz" label="备注">
        </el-table-column>
        <el-table-column
          label="操作" width="170">
          <template slot-scope="scope">
            <el-button v-if="permissions.adis_adreport05_get" type="text" size="small" icon="el-icon-view" @click="showViewBox(scope.row)">查看</el-button>
<!--            <el-button v-if="permissions.adis_adreport05_add" type="text" size="small" icon="el-icon-edit" @click="showEditBox(scope.row)">编辑</el-button>-->
<!--            <el-button v-if="permissions.adis_adreport05_del" type="text" size="small" icon="el-icon-delete"@click="handleDelete(scope.row)">删除</el-button>-->
          </template>
        </el-table-column>
      </el-table>
      <div class="container-page">
        <el-pagination
          @size-change="sizeChange"
          @current-change="currentChange"
          :current-page="page.current"
          :page-sizes="[10, 20, 30, 40, 50, 100]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="page.total">
        </el-pagination>
      </div>
    </div>

    <el-dialog :title="formTitle" :visible.sync="formBox" :close-on-click-modal="!formBox"
               :append-to-body="true" :before-close="resetForm" width="1200px" top="5vh">
      <el-form ref="optForm" :model="form" label-width="130px">
        <el-form-item label="主键id" prop="id" :rules="{required: true, message: '主键id不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.id" placeholder="主键id"></el-input>
        </el-form-item>
        <el-form-item label="学校标识码" prop="xxbsm" :rules="{required: true, message: '学校标识码不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.xxbsm" placeholder="学校标识码"></el-input>
        </el-form-item>
        <el-form-item label="学校名称" prop="xxmc" :rules="{required: true, message: '学校名称不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.xxmc" placeholder="学校名称"></el-input>
        </el-form-item>
        <el-form-item label="统一社会信用代码" prop="tyshxydm" :rules="{required: true, message: '统一社会信用代码不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.tyshxydm" placeholder="统一社会信用代码"></el-input>
        </el-form-item>
        <el-form-item label="单据号" prop="djh" :rules="{required: true, message: '单据号不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.djh" placeholder="单据号"></el-input>
        </el-form-item>
        <el-form-item label="交易站点" prop="jyzd" :rules="{required: true, message: '交易站点不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.jyzd" placeholder="交易站点"></el-input>
        </el-form-item>
        <el-form-item label="卡户账号" prop="khzh" :rules="{required: true, message: '卡户账号不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.khzh" placeholder="卡户账号"></el-input>
        </el-form-item>
        <el-form-item label="卡户姓名" prop="khxm" :rules="{required: true, message: '卡户姓名不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.khxm" placeholder="卡户姓名"></el-input>
        </el-form-item>
        <el-form-item label="卡户身份" prop="khsf" :rules="{required: true, message: '卡户身份不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.khsf" placeholder="卡户身份"></el-input>
        </el-form-item>
        <el-form-item label="身份证号码" prop="sfzhm" :rules="{required: true, message: '身份证号码不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.sfzhm" placeholder="身份证号码"></el-input>
        </el-form-item>
        <el-form-item label="交易类型" prop="jylx" :rules="{required: true, message: '交易类型不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.jylx" placeholder="交易类型"></el-input>
        </el-form-item>
        <el-form-item label="交易时间" prop="jysj" :rules="{required: true, message: '交易时间不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.jysj" placeholder="交易时间"></el-input>
        </el-form-item>
        <el-form-item label="交易金额" prop="jyje" :rules="{required: true, message: '交易金额不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.jyje" placeholder="交易金额"></el-input>
        </el-form-item>
        <el-form-item label="卡余额" prop="kaye" :rules="{required: true, message: '卡余额不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.kaye" placeholder="卡余额"></el-input>
        </el-form-item>
        <el-form-item label="库余额" prop="kuye" :rules="{required: true, message: '库余额不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.kuye" placeholder="库余额"></el-input>
        </el-form-item>
        <el-form-item label="优惠金额" prop="yhje" :rules="{required: true, message: '优惠金额不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.yhje" placeholder="优惠金额"></el-input>
        </el-form-item>
        <el-form-item label="商户账号" prop="shzh" :rules="{required: true, message: '商户账号不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.shzh" placeholder="商户账号"></el-input>
        </el-form-item>
        <el-form-item label="商户名称" prop="shmc" :rules="{required: true, message: '商户名称不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.shmc" placeholder="商户名称"></el-input>
        </el-form-item>
        <el-form-item label="商户统一社会信用代码" prop="shtyshxydm" :rules="{required: true, message: '商户统一社会信用代码不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.shtyshxydm" placeholder="商户统一社会信用代码"></el-input>
        </el-form-item>
        <el-form-item label="到账时间" prop="dzsj" :rules="{required: true, message: '到账时间不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.dzsj" placeholder="到账时间"></el-input>
        </el-form-item>
        <el-form-item label="备注" prop="bz" :rules="{required: true, message: '备注不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.bz" placeholder="备注"></el-input>
        </el-form-item>
        <el-form-item label="创建日期" prop="createtime" :rules="{required: true, message: '创建日期不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.createtime" placeholder="创建日期"></el-input>
        </el-form-item>
        <el-form-item label="修改日期" prop="modifytime" :rules="{required: true, message: '修改日期不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.modifytime" placeholder="修改日期"></el-input>
        </el-form-item>
        <el-form-item label="操作状态" prop="czzt" :rules="{required: true, message: '操作状态不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.czzt" placeholder="操作状态"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
          <el-button @click="resetForm" size="small" icon="el-icon-close">关闭</el-button>
         <el-button v-if="!isView" type="primary" @click="submit" size="small" icon="el-icon-check">保存</el-button>
      </span>
    </el-dialog>

    <el-dialog :title="formTitle" :visible.sync="viewBox" :close-on-click-modal="!viewBox"
               :append-to-body="true" :before-close="resetForm" width="1200px" top="5vh">
      <el-form ref="optForm" :model="form" label-width="130px">
        <el-form-item label="主键id" prop="id" :rules="{required: true, message: '主键id不能为空', trigger: ['blur', 'change']}">
          {{form.id}}
        </el-form-item>
        <el-form-item label="学校标识码" prop="xxbsm" :rules="{required: true, message: '学校标识码不能为空', trigger: ['blur', 'change']}">
          {{form.xxbsm}}
        </el-form-item>
        <el-form-item label="学校名称" prop="xxmc" :rules="{required: true, message: '学校名称不能为空', trigger: ['blur', 'change']}">
          {{form.xxmc}}
        </el-form-item>
        <el-form-item label="统一社会信用代码" prop="tyshxydm" :rules="{required: true, message: '统一社会信用代码不能为空', trigger: ['blur', 'change']}">
          {{form.tyshxydm}}
        </el-form-item>
        <el-form-item label="单据号" prop="djh" :rules="{required: true, message: '单据号不能为空', trigger: ['blur', 'change']}">
          {{form.djh}}
        </el-form-item>
        <el-form-item label="交易站点" prop="jyzd" :rules="{required: true, message: '交易站点不能为空', trigger: ['blur', 'change']}">
          {{form.jyzd}}
        </el-form-item>
        <el-form-item label="卡户账号" prop="khzh" :rules="{required: true, message: '卡户账号不能为空', trigger: ['blur', 'change']}">
          {{form.khzh}}
        </el-form-item>
        <el-form-item label="卡户姓名" prop="khxm" :rules="{required: true, message: '卡户姓名不能为空', trigger: ['blur', 'change']}">
          {{form.khxm}}
        </el-form-item>
        <el-form-item label="卡户身份" prop="khsf" :rules="{required: true, message: '卡户身份不能为空', trigger: ['blur', 'change']}">
          {{form.khsf}}
        </el-form-item>
        <el-form-item label="身份证号码" prop="sfzhm" :rules="{required: true, message: '身份证号码不能为空', trigger: ['blur', 'change']}">
          {{form.sfzhm}}
        </el-form-item>
        <el-form-item label="交易类型" prop="jylx" :rules="{required: true, message: '交易类型不能为空', trigger: ['blur', 'change']}">
          {{form.jylx}}
        </el-form-item>
        <el-form-item label="交易时间" prop="jysj" :rules="{required: true, message: '交易时间不能为空', trigger: ['blur', 'change']}">
          {{form.jysj}}
        </el-form-item>
        <el-form-item label="交易金额" prop="jyje" :rules="{required: true, message: '交易金额不能为空', trigger: ['blur', 'change']}">
          {{form.jyje}}
        </el-form-item>
        <el-form-item label="卡余额" prop="kaye" :rules="{required: true, message: '卡余额不能为空', trigger: ['blur', 'change']}">
          {{form.kaye}}
        </el-form-item>
        <el-form-item label="库余额" prop="kuye" :rules="{required: true, message: '库余额不能为空', trigger: ['blur', 'change']}">
          {{form.kuye}}
        </el-form-item>
        <el-form-item label="优惠金额" prop="yhje" :rules="{required: true, message: '优惠金额不能为空', trigger: ['blur', 'change']}">
          {{form.yhje}}
        </el-form-item>
        <el-form-item label="商户账号" prop="shzh" :rules="{required: true, message: '商户账号不能为空', trigger: ['blur', 'change']}">
          {{form.shzh}}
        </el-form-item>
        <el-form-item label="商户名称" prop="shmc" :rules="{required: true, message: '商户名称不能为空', trigger: ['blur', 'change']}">
          {{form.shmc}}
        </el-form-item>
        <el-form-item label="商户统一社会信用代码" prop="shtyshxydm" :rules="{required: true, message: '商户统一社会信用代码不能为空', trigger: ['blur', 'change']}">
          {{form.shtyshxydm}}
        </el-form-item>
        <el-form-item label="到账时间" prop="dzsj" :rules="{required: true, message: '到账时间不能为空', trigger: ['blur', 'change']}">
          {{form.dzsj}}
        </el-form-item>
        <el-form-item label="备注" prop="bz" :rules="{required: true, message: '备注不能为空', trigger: ['blur', 'change']}">
          {{form.bz}}
        </el-form-item>
        <el-form-item label="创建日期" prop="createtime" :rules="{required: true, message: '创建日期不能为空', trigger: ['blur', 'change']}">
          {{form.createtime}}
        </el-form-item>
        <el-form-item label="修改日期" prop="modifytime" :rules="{required: true, message: '修改日期不能为空', trigger: ['blur', 'change']}">
          {{form.modifytime}}
        </el-form-item>
        <el-form-item label="操作状态" prop="czzt" :rules="{required: true, message: '操作状态不能为空', trigger: ['blur', 'change']}">
          {{form.czzt}}
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
          <el-button @click="resetForm" size="small" icon="el-icon-close">关闭</el-button>
      </span>
    </el-dialog>
    <!--excel 模板导入 -->
    <excel-upload
      ref="excelUpload"
      title="用户信息导入"
      url="/exam/adReport05/import"
      temp-name="用户信息.xlsx"
      temp-url="/admin/sys-file/local/user.xlsx"

    ></excel-upload>
  </basic-container>
</template>

<script>
import {delObj, fetchList, getObj, submit} from "@/api/data/oneCard/jylsb";
import {mapGetters} from "vuex";
import ExcelUpload from "@/components/upload/excel.vue";

export default {
  components: {
    ExcelUpload
  },
  dictTypes: [],
  data() {
    return {
      importBox: false,
      isEdit: false,
      isView: false,
      viewBox: false,
      formBox: false,
      formTitle: '',
      loading: false,
      query: {},
      form: {},
      page: {
        size: 10,
        current: 1,
        total: 0
      },
      data: [],
      Authorization: 'Bearer ' + this.$store.getters.access_token,
    }
  },
  computed: {
    ...mapGetters(["permissions"])
  },
  created() {
    this.onLoad(this.page);
  },
  methods: {
    submit() {
      this.$refs['optForm'].validate((valid) => {
        if (valid) {
          this.loading = true;
          this.fileList && this.fileList.map((file) => {
            this.form.cover = file.response ? file.response.data.url : file.url
          });
          this.fileListVideo && this.fileListVideo.map((file) => {
            this.form.videoUrl = file.response ? file.response.data.url : file.url
          });
          submit(this.form).then(() => {
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.resetForm();
            this.onLoad(this.page);
          }, () => {
            this.loading = false;
          });
        } else {
          return false;
        }
      });
    },
    showAddView() {
      this.formTitle = '新增';
      this.formBox = true;
    },
    showEditBox(row) {
      getObj(row.id).then((res) => {
        this.form = res.data.data;
        this.formTitle = '编辑';
        this.formBox = true;
        this.isEdit = true;
        // this.fileList = [];
        // if (res.data.data.cover) {
        //   this.fileList.push({url: res.data.data.cover});
        // }
        //
        // this.fileListVideo = [];
        // this.fileListVideo.push({url: res.data.data.videoUrl});
      });
    },
    showViewBox(row) {
      getObj(row.id).then((res) => {
        this.form = res.data.data;
        this.formTitle = "查看";
        this.viewBox = true;
        // this.fileList = [];
        // if (res.data.data.cover) {
        //   this.fileList.push({url: res.data.data.cover});
        // }
        //
        // this.fileListVideo = [];
        // this.fileListVideo.push({url: res.data.data.videoUrl});
      });
    },
    handleDelete(row) {
      this.$confirm("确定将选择的数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        return delObj(row.id);
      })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
        });
    },
    resetForm() {
      this.formBox = false;
      this.isEdit = false;
      this.isView = false;
      this.form = {
        houseType: 1, // 景点
        tags: []
      };
      this.formTitle = '';
      this.$refs['optForm'] && this.$refs['optForm'].resetFields();
      this.viewBox = false;
      this.fileList = [];
      this.fileListVideo = [];
      this.auditBox = false;

      this.customerBox = false;
      this.customerList = [];

      this.commentBox = false;
      this.commentList = [];
    },
    onSearch() {
      this.page.current = 1;
      this.onLoad(this.page);
    },
    searchReset() {
      this.query = {};
      this.page.current = 1;
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.current = 1;
      this.onLoad(this.page, params);
      done();
    },
    currentChange(current) {
      this.page.current = current;
      this.onLoad(this.page);
    },
    sizeChange(size) {
      this.page.size = size;
      this.onLoad(this.page);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      fetchList(Object.assign(params, this.query, page)).then(res => {
        this.loading = false;
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
      }, () => {
        this.loading = false;
      });
    },
    handleRemove(file, fileList) {
      this.fileList = fileList;
      this.showUploadButton = true
    },
    handleSuccess(response, file, fileList) {
      this.fileList = fileList;
      if (this.fileList.length >= 1) {
        this.showUploadButton = false
      }
    },
    handlePreview(file) {
      window.open(file.url ? file.url : file.response.data.url)
    },
    beforeRemove(file) {
      return this.$confirm(`确定移除 pom.xml？`);
    },
  }
};
</script>

<style>
</style>
